package com.capinfo.accounting.web;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.capinfo.accumulation.model.accounting.Fuzhuzhang;
import com.capinfo.accumulation.model.accounting.Kmyeb;
import com.capinfo.accumulation.parameter.accounting.FuzhuzhangParameter;
import com.capinfo.accumulation.parameter.accounting.KmyebParameter;
import com.capinfo.accumulation.service.accounting.KmyebService;
import com.capinfo.accumulation.util.ExcelUtil;
import com.capinfo.framework.service.CommonsDataOperationService;
import com.capinfo.framework.web.controller.CommonsDataManageController;


/**
 * 科目余额账表控制器
 * @author
 */
@Controller
@RequestMapping("/business/accounting/kmyeb")
public class KmyebController extends CommonsDataManageController<KmyebParameter, Kmyeb> {

	@Autowired
	private KmyebService kmyebService;

	@Override
	public CommonsDataOperationService<Kmyeb, KmyebParameter> getCommonsDataOperationService() {
		return kmyebService;
	}
	
	/**
	 * excel导出
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping({ "/excels.shtml" })
	@ResponseBody
	public void excels(HttpServletRequest request,HttpServletResponse response,KmyebParameter parameter) throws IOException {
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		List<Kmyeb> entities = new ArrayList<Kmyeb>();
		long totalCount = getCommonsDataOperationService().getTotalCount(parameter);
		if (0 != totalCount) {
			entities = getCommonsDataOperationService().getList(parameter, totalCount, parameter.getCurrentPieceNum());
		}
		Map beanParams = new HashMap();
		beanParams .put("liste", entities);
		//Excel名称
		String excelName = "科目余额表.xls";
		ExcelUtil.createExcel(ExcelUtil.readValueMB() + excelName, beanParams, ExcelUtil.readValueSC() + excelName);
		PrintWriter pw;
		pw = response.getWriter();
		pw.write(excelName);
	}

}
